package com.example.explainus;

import com.example.units.GlobalParameters;
import com.example.units.GlobalVariables;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

public class PrepareRoundActivity extends Activity 
{

	private static int roundNum = 1;
	private int teamNumb;
	private TextView results;
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_prepareround);
		GlobalParameters.overrideFonts(this, findViewById(R.id.textView1));
		GlobalParameters.overrideFonts(this, findViewById(R.id.tReadyToGo));
		GlobalParameters.overrideFonts(this, findViewById(R.id.bGoRound));
		GlobalParameters.overrideFonts(this, findViewById(R.id.bBackFromRound));
		GlobalParameters.overrideFonts(this, findViewById(R.id.tResults));
		TextView numbRnd = (TextView)findViewById(R.id.tRoundNumber);
		numbRnd.setText(Integer.toString(roundNum));
		results = (TextView)findViewById(R.id.tResults);
		teamNumb = GlobalVariables.info.getFirstTeam();
		Log.d("DEBUG_PREPARE", "HERE BEFORE");
		if (GlobalVariables.info.getMaxScore() < GlobalVariables.countWords)
		{
			if (teamNumb!=GlobalVariables.gameNow)
			{
				results.setText(getResources().getString(R.string.tbeforeresults) + GlobalVariables.info.getScore(GlobalVariables.gameNow));
			}
			GlobalVariables.gameNow = teamNumb;
			TextView dopRnd = (TextView)findViewById(R.id.tReadyToGo);
			if (teamNumb == -1)
			{
				roundNum++;
				numbRnd.setText(Integer.toString(roundNum));
				GlobalVariables.info.setRoundFalseForAll();
				teamNumb = GlobalVariables.info.getFirstTeam();
				GlobalVariables.gameNow = teamNumb;
				dopRnd.setText(dopRnd.getText() + Integer.toString(teamNumb + 1));
				GlobalVariables.info.setCurrentTeam(teamNumb);
				results.setText("");
			}
			else
			{
				dopRnd.setText(dopRnd.getText() + Integer.toString(teamNumb + 1));
				Log.d("DEBUG_PREPARE_ELSE", Integer.toString(teamNumb));
				GlobalVariables.info.setCurrentTeam(teamNumb);
				GlobalVariables.gameNow = teamNumb;
			}
		}
		else
		{
			Intent start = new Intent(PrepareRoundActivity.this, GameResultsActivity.class);
			startActivity(start);
			finish();
		}
		
	}
	
	public void goRound(View view)
	{
		Intent next = new Intent(PrepareRoundActivity.this, RoundActivity.class);
		startActivity(next);
		finish();
	}
	
	public void exitGame(View view)
	{
		if (GlobalVariables.info != null)
			GlobalVariables.info.eraseAll();
		Intent back = new Intent(PrepareRoundActivity.this, NewGameActivity.class);
		startActivity(back);
		roundNum = 1;
		finish();
	}
	
}
